<?php
class ProjectAction extends CommonAction{
	//方案评论
	public function pubProjectComment(){
		//权限过滤
		$project = M('Project')->where('Id='.$this->_post('projectid'))->find();
		$team = M('Team')->where('Id='.$project['TeamId'])->find();
		$user = $_SESSION[C('USER_AUTH_KEY')];
		//组装数据
		$data['ProjectId'] = $this->_post('projectid');
		$data['ProjectName'] = $project['Name']; 
		$data['Content'] = $this->_post('content'); 
		$data['CreateUser'] = $team['Captain'];
		//只有详细信息学生可以评论
		if($user['UserType'] == 1){
			$this->ajaxReturn(array('user'=>'普通学生'),'个人信息不完整，不能评论！',-2);
		}else{
			if($user['UserType']==2){
				$data['IsStudent'] = 1;
			}else{
				$data['IsStudent'] = 0;
			}
		}	
		$data['UserName'] = $user['TrueName'];
		$data['UserId'] = $user['UserId'];
		$data['OrgName'] = $user['OrgName'];
		$data['Score'] = 0;
		$data['IsDeleted'] = 0;
		$data['Version'] = '1.0';
		$data['CreateDate'] = date('Y-m-d H:i:s');
		$res = M('Projectcomment')->add($data);
		if($res){
			M('Project')->where('Id='.$this->_post('projectid'))->setInc('CommentCount');
			$this->ajaxReturn($data,'评论成功',1);
		}else{
			$this->ajaxReturn($data,'评论失败',-1);
		}
		
	}
}